
import axios from "axios";
import baseUrl from "@/config/congfig";
import { getToken } from "./token";
import { message } from "antd";
let baseURL = baseUrl('local')

const http = axios.create({
    // baseURL: baseURL,
    timeout: 5000
})

//请求拦截器
http.interceptors.request.use((config)=>{
    console.log(config,'----------request--------------');
    const token = getToken()
    if(token){
        config.headers.Authorization = token
    }
    return config
},(error)=>{
    return Promise.reject(error)
})

//相应拦截器
http.interceptors.response.use((response)=>{
    console.log(response,'----------response--------------');
    const res = response.data
    if (res.code !== 200) {
      message.error(res.message)
    } else {
      return res
    }
},(error)=>{
    return Promise.reject(error)
})

export {http}